Piddling Pertinent
  • Home
  • Categories
  • Tags
  • Archives

Animated Heart in Python

In [2]:
# Credits: http://www.walkingrandomly.com/?p=5964 
# and http://jakevdp.github.io/blog/2013/05/19/a-javascript-viewer-for-matplotlib-animations/
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
from JSAnimation import IPython_display


fig = plt.figure()
ax = plt.axes(xlim=(-2, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2, color='red')

def init():
    line.set_data([], [])
    return line,

def animate(i):
    x = np.linspace(-2, 2, 1000)
    y = (np.sqrt(np.cos(x))*np.cos(i*x)+np.sqrt(np.abs(x))-0.7)*(4-x*x)**0.01
    line.set_data(x, y)
    return line,

animation.FuncAnimation(fig, animate, init_func=init,
                        frames=100, interval=30)
Out[2]:


Once Loop Reflect

Share on: Twitter ❄ Facebook ❄ Google+ ❄ Email


Related Posts

  • Expectation Maximisation in Python: Coin Toss Example
  • #AcademicValentines
  • Andrews Curves
  • Expected number of flips in a memoryless concentration game
  • Fourier transform and choice of window function

  • « Expectation Maximisation in Python: Coin Toss Example
  • #AcademicValentines »

Published

Feb 8, 2016

Category

misc

Tags

  • animation 2
  • python 6

Contact

  • Piddling Pertinent - trivially relevant
  • Powered by Pelican. Theme: Elegant